using System.Collections.Generic;
using System.Linq;
using Magiq.Behaviors;

namespace Magiq.Delete
{
    public class Delete<T> : BehaviorHandler<IDeleteBehavior>, IDelete<T> where T : class
    {
        public Delete(IQueryable<T> source, IMagiqBehavior behavior)
            : base(behavior)
        {
            Default<DefaultDeleteBehavior>();
            Source = source;
        }

        #region IDelete<T> Members

        public int Execute()
        {
            var strategy = Call(x => x.GetDeleteStrategy(this));
            return Call(x => x.Execute(strategy));
        }

        public IQueryable<T> Source { get; private set; }

        IMagiqBehavior IBehaviorBasedExecution.Behavior
        {
            get { return BehaviorChain; }
        }

        #endregion
    }
}